package BasicKnowledge;

import java.util.Arrays;
public class Test {
    public static void main(String[] args) {
        //在主类中尝试
        System.out.println("交换前");
        int[] arr1={1,2,3,4,5,6};
        int[] arr2 ={2,6,4,8,9,4};
        System.out.println(Arrays.toString(arr1));
        System.out.println(Arrays.toString(arr2));


        swap(arr1,arr2);

        System.out.println("交换后");
        System.out.println(Arrays.toString(arr1));
        System.out.println(Arrays.toString(arr2));




    }

    public static void swap(int[] array1,int[] array2){
//        System.out.println("交换前");
//        System.out.println(Arrays.toString(array1));
//        System.out.println(Arrays.toString(array2));
        int tmp = 0;
        for (int i = 0; i < array1.length; i++) {
            tmp = array1[i];
            array1[i] = array2[i];
            array2[i] = tmp;
        }

//        System.out.println("交换后");
//        System.out.println(Arrays.toString(array1));
//        System.out.println(Arrays.toString(array2));


    }
    public static int[] transform(int[] a){
        int left=0;
        int right=a.length-1;
        while(left<right){
            //该循环结束，left指向一个奇数  等于0进入，不等于0退出，就保存的是奇数的下标
            while(left<right&&a[left]%2==0){
                left++;
            }
            //该循环结束，right指向一个偶数    不等于0进入，等于0退出，就保存的是偶数的下标
            while(left<right&&a[right]%2!=0){
                right--;
            }
            /// 交换两个元素的位置
            int temp=a[left];
            a[left]=a[right];
            a[right]=temp;
        }
        return a;
    }
}
